package com.xul.crowd.service.Impl;

import com.xul.crowd.mapper.MemberPOMapper;
import com.xul.crowd.service.MemberService;
import com.xul.entity.po.MemberPO;
import com.xul.entity.po.MemberPOExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xul
 * @create 2021-07-29 15:17
 * 事务设置只读
 */
@Transactional(readOnly = true)
@Service()
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberPOMapper memberPOMapper;

    /**
     * 保存会员信息到数据库 给auth远程调用
     *
     * @param memberPO
     */
    @Transactional(propagation = Propagation.REQUIRES_NEW,
            rollbackFor = Exception.class,
            readOnly = false)
    @Override
    public void saveMember(MemberPO memberPO) {
        memberPOMapper.insertSelective(memberPO);
    }

    /**
     * 根据会员的账号 查询账号信息 给auth远程调用
     *
     * @param loginAcct
     * @return
     */
    @Override
    public MemberPO getMemberPOBByLoginAcct(String loginAcct) {
        MemberPOExample memberPOExample = new MemberPOExample();
        MemberPOExample.Criteria criteria = memberPOExample.createCriteria();
        criteria.andLoginacctEqualTo(loginAcct);
        List<MemberPO> memberPOList = memberPOMapper.selectByExample(memberPOExample);
        if (memberPOList == null || memberPOList.size() == 0) {
            return null;
        }
        return memberPOList.get(0);
    }
}
